package cn.tedu.map;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * @author :Colin
 * @version 创建时间: 2021/6/22 18:34
 */
public class HomeWorkMap {
    public static void main(String[] args) {
        Map<Integer,String> map =new HashMap<>();
        map.put(1,"农夫山泉");
        map.put(2,"健力宝");
        map.put(3,"果粒橙");
        map.put(4,"脉动");
        //方式一：Set<key> KeySet方法
        Set<Integer> in = map.keySet();
        Iterator<Integer> it = in.iterator();
        while(it.hasNext()){
            Integer key = it.next();
            String value = map.get(key);
            System.out.println("{"+key+"+"+value+"}");
        }
        //方式二：Set<Entry<k,v>> EntrySet方法
        Set<Map.Entry<Integer, String>> entries = map.entrySet();
        Iterator<Map.Entry<Integer, String>> it2 = entries.iterator();
        while(it2.hasNext()){
            Map.Entry<Integer, String> next = it2.next();
            Integer key = next.getKey();
            String value = next.getValue();
            System.out.println("{"+key+"+"+value+"}");
        }
    }

}
